package _0070;

/**
 * Created by HMF on 2021/05/22 09:12
 */
public class Solution {
    public static int climbStairs(int n) {

        if (n == 1 || n == 2) {
            return n;
        }

        /**
         * 下面处理 n >= 3 的情况
         */
        int one = 2; // 初始化为走到第二级台阶的走法
        int two = 1; // 初始化为走到第一级台阶的走法

        int sum = 0;

        for (int i = 3; i <= n; i++) {
            // 最后跨2步 + 最后跨1步 的走法
            sum = two + one;
            two = one;
            one = sum;
        }
        return sum;
    }

    // leetcode 题解
    public static int climbStairsPlus(int n) {
        int p = 0, q = 0, r = 1;
        for (int i = 1; i <= n; ++i) {
            p = q;
            q = r;
            r = p + q;
        }
        return r;
    }


    public static void main(String[] args) {
//        int n = 1;
//        int n = 2;
        int n = 5;
        System.out.println("climbStairs()：" + climbStairs(n));
        System.out.println("climbStairsPlus()：" + climbStairsPlus(n));
    }
}
